<!-- <template>
	<view>
		<uni-section title="*标签编码" type="line">
			<uni-easyinput class="tagCode" v-model="tagCode" :inputBorder="false" :border="true" placeholder="扫码或手动输入标签编码" @iconClick="onClick">
			</uni-easyinput>
			<button @click="scan">扫码</button>
			
		</uni-section>
		<uni-section title="*标签名称" type="line">
			<uni-easyinput class="tagCode" v-model="tagName" :inputBorder="false" :border="true" placeholder="请输入标签名称" @iconClick="onClick">
			</uni-easyinput>
		</uni-section>

		<button @click="save">保存</button>
	</view>

</template> -->
<template>
	<view class="container">
		<uni-forms ref="form" :modelValue="formData" :rules="rules">
			<uni-forms-item label="标签编码" class="tagCode">
				<uni-easyinput suffixIcon="scan" @iconClick="scan" type="text" v-model="formData.tagCode" placeholder="扫码或手动输入标签编码" />
			</uni-forms-item>
			<uni-forms-item label="标签名称" class="tagName">
				<uni-easyinput type="text" v-model="formData.tagName" placeholder="请输入标签名称" />
			</uni-forms-item>
		</uni-forms>
		<button @click="submit()" size="small" style="width: 100%;" type="primary">保存</button>
	</view>
</template>

<script>
	import request from "@/common/request.js";
	export default {
		data() {
			return {
				// 表单数据
				formData: {
					tagName: '',
					tagCode: ''
				},
				rules: {
					// 对tagCode字段进行必填验证
					tagCode: {
						rules: [{
								required: true,
								errorMessage: '扫码或手动输入标签编码',
							},
						]
					},
					tagName: {
						rules: [{
								required: true,
								errorMessage: '请输入标签名称',
							},
						]
					},
				},
				label_data: [{
					labelName:'',
					deviceNo:'',
					groupID:'',
					longitude:'',
					remark:'',
				}]
			}
		},
		methods: {
			// 触发提交表单
			submit() {
				this.$refs.form.validate().then(res => {
					co6nsole.log('表单数据信息：', res);
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
				
				let opts = {
					url: "/business/label",
					method: "post"
				};
				
				console.log("上传新建信息");
				
				uni.showLoading({
					title : '加载中'
				});
				
				request.httpTokenRequest(opts,this.label_data).then(res => {
								uni.hideLoading();
								if (res.code == 200) {
									console.log(res);
								} else {
									console.log("请求失败");
								}
							});
				
				uni.navigateBack({})
				console.log("you clicked save, then we will back..");
			},
			// 扫码
			scan() {
				console.log("you clicked scan..");
			},

		}
		
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}

	.tagCode {
		margin: auto;
	}
</style>
